﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using OrganizedIN.DAL;
using OrganizedIN.BAL;
using OrganizedIN.BussinessServices;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using OrganizedIN.BAL.Common;

namespace OrganizedIN.UI.ToDo
{
    public partial class mark_todos : System.Web.UI.Page
    {
        string strUserName;
       
        protected void Page_Load(object sender, EventArgs e)
        {
            strUserName = Session["UserID"].ToString();

            if (!IsPostBack)
            {
                BindList();
            }
        }
        public void BindList()
        {
            try
            {
                DataSet ds = new DataSet();
                ds = Common.Get_Todo_SearchResult(strUserName, "", "", "", 0, "0");
                gvTodoList.DataSource = ds.Tables[0];
                gvTodoList.DataBind();
                if (ds.Tables[0].Rows.Count > 0)
                {
                    lblErrMsg.Text = "";
                }
                else
                {
                    lblErrMsg.Text = "No record(s) found.";
                }
            }
            catch (Exception ex)
            {
                lblErrMsg.Text = ex.ToString();
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string strIDs = "";
                int count = 0;

                for (int i = 0; i < gvTodoList.Rows.Count; i++)
                {
                    CheckBox chk = (CheckBox)gvTodoList.Rows[i].Cells[0].FindControl("chkID");

                    if (chk != null)
                    {
                        if (chk.Checked)
                        {
                            strIDs = strIDs + gvTodoList.Rows[i].Cells[1].Text + "~";
                            //strID = strID + gvTodoList.Rows[i].FindControl("Todo_ID").ToString() + "~";
                            count++;
                        }
                    }
                }
                if (count > 0)
                {
                    Common.Todo_Mark_Completed(strIDs);
                }
                BindList();
            }
            catch (Exception ex)
            {
                lblErrMsg.Text = ex.ToString();
            }
        }

        protected void gvTodoList_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            gvTodoList.PageIndex = e.NewPageIndex;
            strUserName = Convert.ToString(Session["UserID"]);
            BindList();
        }

        
    }  
}
